package com.hnas.sys.orm;
// default package

import static javax.persistence.GenerationType.IDENTITY;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.hnas.core.util.StringUtil;
import com.hnas.sys.domain.ResourceStatus;

//import freemarker.template.utility.StringUtil;


/**
 * Authority entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name="sys_authority"

)

public class Authority  implements java.io.Serializable {


    /**
	 * 
	 */
	private static final long serialVersionUID = -6125619204695573744L;
	// Fields    
    @Id @GeneratedValue(strategy=IDENTITY)    
    @Column(name="id",nullable=false)
     private long id;
     private String name;
     private String description;
     @Transient
     private ResourceStatus status;
     @Column(name="status", length=5)
     private String statusStr;
     @Transient
     private String resourceIDs;
     @ManyToMany(cascade = CascadeType.REFRESH, mappedBy = "authoritys",fetch = FetchType.LAZY)
     private Set<User> users = new HashSet<User>(0);
     @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="authority")
     private Set<AuthorityResource> authorityResources = new HashSet<AuthorityResource>(0);


    // Constructors

    /** default constructor */
    public Authority() {
    }

    
    /** full constructor */
    public Authority(String name, String description, String status, Set<UserAuthority> userAuthorities, Set<AuthorityResource> authorityResources) {
        this.name = name;
        this.description = description;
        this.statusStr = status;
        this.users = users;
        this.authorityResources = authorityResources;
    }

   
    // Property accessors
//    @Id @GeneratedValue(strategy=IDENTITY)
//    
//    @Column(name="id", unique=true, nullable=false)

    public long getId() {
        return this.id;
    }
    
    public void setId(long id) {
        this.id = id;
    }
    
//    @Column(name="name", length=50)

    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
//    @Column(name="description", length=200)

    public String getDescription() {
        return this.description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }

	/**
	 * @return the status
	 */
//    @Transient
	public ResourceStatus getStatus() {
		if(!StringUtil.isEmpty(statusStr)) {
			return ResourceStatus.valueOfAlias(statusStr);
		}
		return status;
	}


	/**
	 * @param status the status to set
	 */
	public void setStatus(ResourceStatus status) {
		this.status = status;
		if(null != status) {
			this.statusStr = status.toString();
		}
	}


	/**
	 * @return the statusStr
	 */
  
	public String getStatusStr() {
		return statusStr;
	}


	/**
	 * @param statusStr the statusStr to set
	 */
	public void setStatusStr(String statusStr) {
		this.statusStr = statusStr;
		if(StringUtil.isNotEmpty(statusStr)) {
			this.status = ResourceStatus.valueOfAlias(statusStr);
		}
	}    

    /**
	 * @return the resourceIDs
	 */
	
	public String getResourceIDs() {
		return resourceIDs;
	}


	/**
	 * @param resourceIDs the resourceIDs to set
	 */
	public void setResourceIDs(String resourceIDs) {
		this.resourceIDs = resourceIDs;
	}


	/**
	 * @return the serialversionuid
	 */
	public static long getSerialversionuid() {
		return serialVersionUID;
	}


	/**
	 * @return the users
	 */
    
	public Set<User> getUsers() {
		return users;
	}

	/**
	 * @param users the users to set
	 */
	public void setUsers(Set<User> users) {
		this.users = users;
	}




    public Set<AuthorityResource> getAuthorityResources() {
        return this.authorityResources;
    }
    
    public void setAuthorityResources(Set<AuthorityResource> authorityResources) {
        this.authorityResources = authorityResources;
    }
   








}